
    //#line 123 "LexerTemplateF.gi

import 'package:lpg2/lpg2.dart';
import 'snooperLexerprs.dart';
import 'snooperLexersym.dart';
import 'snooperKWLexer.dart';
import 'dart:io';

    //#line 6 "snooperLexer.gi



    //#line 2 "LexerBasicMapF.gi
import 'snooperParsersym.dart';

    //#line 133 "LexerTemplateF.gi

class snooperLexer extends Object implements RuleAction
{
    late snooperLexerLpgLexStream lexStream ;
    
    static  ParseTable prs = snooperLexerprs();
    ParseTable  getParseTable() { return snooperLexer.prs; }

    LexParser  lexParser = LexParser();
    LexParser  getParser()  { return lexParser; }

    int getToken(int i)   { return lexParser.getToken(i); }
    int  getRhsFirstTokenIndex(int i) { return lexParser.getFirstToken(i); }
    int  getRhsLastTokenIndex(int i) { return lexParser.getLastToken(i); }

    int getLeftSpan()  { return lexParser.getToken(1); }
    int getRightSpan()   { return lexParser.getLastToken(); }

    void  resetKeywordLexer()   
    {
        if (null ==kwLexer)
              kwLexer = snooperKWLexer(lexStream.getInputChars(), snooperParsersym.TK_IDENTIFIER);
         kwLexer!.setInputChars(lexStream.getInputChars());
    }

  
    
    void  reset(String filename , [int tab=4, String?input_chars])
    {
        lexStream = snooperLexerLpgLexStream(filename,input_chars, tab);
        lexParser.reset(lexStream, snooperLexer.prs,  this);
        resetKeywordLexer();
    }
    
   
    snooperLexer(String filename , [int tab=4, String?input_chars])
    {
        lexStream = snooperLexerLpgLexStream(filename,input_chars, tab);
        lexParser.reset(lexStream, snooperLexer.prs,  this);
        resetKeywordLexer();
    }

   

    ILexStream getILexStream(){ return  lexStream; }

    void initializeLexer(IPrsStream prsStream , int start_offset, int end_offset)    
    {
        if (lexStream.getInputChars() == null)
            throw NullPointerException("LexStream was not initialized");
        lexStream.setPrsStream(prsStream);
        prsStream.makeToken(start_offset, end_offset, 0); // Token list must start with a bad token
    }

    void  addEOF( IPrsStream prsStream , int end_offset)   
    {
        prsStream.makeToken(end_offset, end_offset, snooperParsersym.TK_EOF_TOKEN); // and end with the end of file token
        prsStream.setStreamLength(prsStream.getSize());
    }

    void  lexerWithPosition(IPrsStream prsStream, int start_offset , int end_offset , [Monitor? monitor])   
    {
        if (start_offset <= 1)
             initializeLexer(prsStream, 0, -1);
        else initializeLexer(prsStream, start_offset - 1, start_offset - 1);

        lexParser.parseCharacters(start_offset, end_offset,monitor);

        addEOF(prsStream, (end_offset >= lexStream.getStreamIndex() ? lexStream.getStreamIndex() : end_offset + 1));
    }

    void lexer(IPrsStream prsStream,  [Monitor? monitor])   
    {
       
        initializeLexer(prsStream, 0, -1);
        lexParser.parseCharactersWhitMonitor(monitor);
        addEOF(prsStream, lexStream.getStreamIndex());
    }
   

    /**
     * If a parse stream was not passed to this Lexical analyser then we
     * simply report a lexical error. Otherwise, we produce a bad token.
     */
    void  reportLexicalError(int startLoc, int endLoc)    {
        var prs_stream = lexStream.getIPrsStream();
        if (null ==prs_stream)
            lexStream.reportLexicalError(startLoc, endLoc);
        else {
            //
            // Remove any token that may have been processed that fall in the
            // range of the lexical error... then add one error token that spans
            // the error range.
            //
            for (var i = prs_stream.getSize() - 1; i > 0; i--) {
                if (prs_stream.getStartOffset(i) >= startLoc)
                     prs_stream.removeLastToken();
                else break;
            }
            prs_stream.makeToken(startLoc, endLoc, 0); // add an error token to the prsStream
        }        
    }

    //#line 165 "LexerBasicMapF.gi


    //
    // The Lexer contains an array of characters as the input stream to be parsed.
    // There are methods to retrieve and classify characters.
    // The lexparser "token" is implemented simply as the index of the next character in the array.
    // The Lexer : the abstract class LpgLexStream with an implementation of the abstract
    // method getKind.  The template defines the Lexer class and the lexer() method.
    // A driver creates the action class, "Lexer", passing an Option object to the constructor.
    //
    snooperKWLexer? kwLexer;
    bool printTokens=false;
    static  const   int ECLIPSE_TAB_VALUE= 4;

    List<int> getKeywordKinds(){ 
        if(null ==kwLexer){
            throw  NullPointerException("please initilize kwLexer");
        }
        return kwLexer!.getKeywordKinds(); 
    }



    /**
     * @deprecated function replaced by {@link reset(content : String, filename : String)}
     */
    void initialize(String content, String filename)
    {
        reset(filename,4,content);
    }
    
    void makeToken1(int left_token,int right_token , int kind ) 
    {
        lexStream.makeToken(left_token, right_token, kind);
    }
    
    void makeToken(int arg0, [int? arg1, int? arg2])
    {
        if(arg1 != null && arg2 != null){
        
            makeToken1(arg0,arg1,arg2);
            return ;
        }
        var  startOffset  = getLeftSpan();
        var   endOffset = getRightSpan();
        lexStream.makeToken(startOffset, endOffset, arg0);
        if (printTokens)  printValue(startOffset, endOffset);
    }

    void makeComment(int kind) 
    {
        var startOffset =  getLeftSpan(),
            endOffset =  getRightSpan();
        lexStream.getIPrsStream()?.makeAdjunct(startOffset, endOffset, kind);
    }

    void  skipToken() 
    {
        if (printTokens)  printValue( getLeftSpan(),  getRightSpan());
    }
    
    void  checkForKeyWord1()
    {
        if(null ==kwLexer){
            throw  NullPointerException("please initilize kwLexer");
        }
        var startOffset =  getLeftSpan(),
            endOffset =  getRightSpan();
         var   kwKind = kwLexer!.lexer(startOffset, endOffset);
        lexStream.makeToken(startOffset, endOffset, kwKind);
        if ( printTokens)  printValue(startOffset, endOffset);
    }
    
    //
    // This flavor of checkForKeyWord is necessary when the default kind
    // (which is returned when the keyword filter doesn't match) is something
    // other than _IDENTIFIER.
    //
    void checkForKeyWord([int? defaultKind])
    {
       if(null ==defaultKind){
          checkForKeyWord1();
          return;
       }
        if(null ==kwLexer){
            throw  NullPointerException("please initilize kwLexer");
        }
        var startOffset =  getLeftSpan(),
            endOffset =  getRightSpan();
        var    kwKind =  kwLexer!.lexer(startOffset, endOffset);
        if (kwKind == snooperParsersym.TK_IDENTIFIER)
            kwKind = defaultKind;
        lexStream.makeToken(startOffset, endOffset, kwKind);
        if ( printTokens)  printValue(startOffset, endOffset);
    }
    
    void  printValue(int startOffset, int endOffset) 
    {
         var s = lexStream.getInputChars().substring(startOffset, endOffset  + 1);
         stdout.write(s);
    }

  

    //#line 239 "LexerTemplateF.gi

    void ruleAction(int ruleNumber  )   
    {
        switch(ruleNumber)
        {

            //
            // Rule 1:  Token ::= Identifier
            //
            case 1: {     checkForKeyWord();             break;
            }

            //
            // Rule 2:  Token ::= MacroIdentifier
            //
            case 2: {     makeToken(snooperParsersym.TK_MACRO_IDENTIFIER);             break;
            }

            //
            // Rule 3:  Token ::= " SLBody "
            //
            case 3: { 
                makeToken(snooperParsersym.TK_STRING_LITERAL);
                        break;
            }
            //
            // Rule 4:  Token ::= White
            //
            case 4: {     skipToken();             break;
            }

            //
            // Rule 5:  Token ::= SLC
            //
            case 5: {      skipToken();;             break;
            }

            //
            // Rule 6:  Token ::= Eol
            //
            case 6: {    makeToken(snooperParsersym.TK_CRLF);             break;
            }

            //
            // Rule 7:  Token ::= +
            //
            case 7: { 
                makeToken(snooperParsersym.TK_PLUS);
                  break;
            }
    
            //
            // Rule 8:  Token ::= -
            //
            case 8: { 
                makeToken(snooperParsersym.TK_MINUS);
                  break;
            }
    
            //
            // Rule 9:  Token ::= *
            //
            case 9: { 
                makeToken(snooperParsersym.TK_MULTIPLY);
                  break;
            }
    
            //
            // Rule 10:  Token ::= /
            //
            case 10: { 
                makeToken(snooperParsersym.TK_DIVIDE);
                  break;
            }
    
            //
            // Rule 11:  Token ::= (
            //
            case 11: { 
                makeToken(snooperParsersym.TK_LPAREN);
                  break;
            }
    
            //
            // Rule 12:  Token ::= )
            //
            case 12: { 
                makeToken(snooperParsersym.TK_RPAREN);
                  break;
            }
    
            //
            // Rule 13:  Token ::= =
            //
            case 13: { 
                makeToken(snooperParsersym.TK_EQUAL);
                  break;
            }
    
            //
            // Rule 14:  Token ::= ,
            //
            case 14: { 
                makeToken(snooperParsersym.TK_COMMA);
                  break;
            }
    
            //
            // Rule 15:  Token ::= :
            //
            case 15: { 
                makeToken(snooperParsersym.TK_COLON);
                  break;
            }
    
            //
            // Rule 16:  Token ::= ;
            //
            case 16: { 
                makeToken(snooperParsersym.TK_SEMICOLON);
                  break;
            }
    
            //
            // Rule 17:  Token ::= ^
            //
            case 17: { 
                makeToken(snooperParsersym.TK_XOR);
                  break;
            }
    
            //
            // Rule 18:  Token ::= %
            //
            case 18: { 
                makeToken(snooperParsersym.TK_REMAINDER);
                  break;
            }
    
            //
            // Rule 19:  Token ::= ~
            //
            case 19: { 
                makeToken(snooperParsersym.TK_TWIDDLE);
                  break;
            }
    
            //
            // Rule 20:  Token ::= |
            //
            case 20: { 
                makeToken(snooperParsersym.TK_OR);
                  break;
            }
    
            //
            // Rule 21:  Token ::= &
            //
            case 21: { 
                makeToken(snooperParsersym.TK_AND);
                  break;
            }
    
            //
            // Rule 22:  Token ::= <
            //
            case 22: { 
                makeToken(snooperParsersym.TK_LESS);
                  break;
            }
    
            //
            // Rule 23:  Token ::= >
            //
            case 23: { 
                makeToken(snooperParsersym.TK_GREATER);
                  break;
            }
    
            //
            // Rule 24:  Token ::= .
            //
            case 24: { 
                makeToken(snooperParsersym.TK_DOT);
                  break;
            }
    
            //
            // Rule 25:  Token ::= !
            //
            case 25: { 
                makeToken(snooperParsersym.TK_NOT);
                  break;
            }
    
            //
            // Rule 26:  Token ::= [
            //
            case 26: { 
                makeToken(snooperParsersym.TK_LBRACKET);
                  break;
            }
    
            //
            // Rule 27:  Token ::= ]
            //
            case 27: { 
                makeToken(snooperParsersym.TK_RBRACKET);
                  break;
            }
    
            //
            // Rule 28:  Token ::= {
            //
            case 28: { 
                makeToken(snooperParsersym.TK_LBRACE);
                  break;
            }
    
            //
            // Rule 29:  Token ::= }
            //
            case 29: { 
                makeToken(snooperParsersym.TK_RBRACE);
                  break;
            }
    
            //
            // Rule 30:  Token ::= ?
            //
            case 30: { 
                makeToken(snooperParsersym.TK_QUESTION);
                  break;
            }
    
            //
            // Rule 31:  Token ::= @
            //
            case 31: { 
                makeToken(snooperParsersym.TK_AT);
                  break;
            }
    
            //
            // Rule 32:  Token ::= + +
            //
            case 32: { 
                makeToken(snooperParsersym.TK_PLUS_PLUS);
                  break;
            }
    
            //
            // Rule 33:  Token ::= - -
            //
            case 33: { 
                makeToken(snooperParsersym.TK_MINUS_MINUS);
                  break;
            }
    
            //
            // Rule 34:  Token ::= = =
            //
            case 34: { 
                makeToken(snooperParsersym.TK_EQUAL_EQUAL);
                  break;
            }
    
            //
            // Rule 35:  Token ::= < =
            //
            case 35: { 
                makeToken(snooperParsersym.TK_LESS_EQUAL);
                  break;
            }
    
            //
            // Rule 36:  Token ::= ! =
            //
            case 36: { 
                makeToken(snooperParsersym.TK_NOT_EQUAL);
                  break;
            }
    
            //
            // Rule 37:  Token ::= < <
            //
            case 37: { 
                makeToken(snooperParsersym.TK_LEFT_SHIFT);
                  break;
            }
    
            //
            // Rule 38:  Token ::= + =
            //
            case 38: { 
                makeToken(snooperParsersym.TK_PLUS_EQUAL);
                  break;
            }
    
            //
            // Rule 39:  Token ::= - =
            //
            case 39: { 
                makeToken(snooperParsersym.TK_MINUS_EQUAL);
                  break;
            }
    
            //
            // Rule 40:  Token ::= * =
            //
            case 40: { 
                makeToken(snooperParsersym.TK_MULTIPLY_EQUAL);
                  break;
            }
    
            //
            // Rule 41:  Token ::= / =
            //
            case 41: { 
                makeToken(snooperParsersym.TK_DIVIDE_EQUAL);
                  break;
            }
    
            //
            // Rule 42:  Token ::= & =
            //
            case 42: { 
                makeToken(snooperParsersym.TK_AND_EQUAL);
                  break;
            }
    
            //
            // Rule 43:  Token ::= | =
            //
            case 43: { 
                makeToken(snooperParsersym.TK_OR_EQUAL);
                  break;
            }
    
            //
            // Rule 44:  Token ::= ^ =
            //
            case 44: { 
                makeToken(snooperParsersym.TK_XOR_EQUAL);
                  break;
            }
    
            //
            // Rule 45:  Token ::= % =
            //
            case 45: { 
                makeToken(snooperParsersym.TK_REMAINDER_EQUAL);
                  break;
            }
    
            //
            // Rule 46:  Token ::= < < =
            //
            case 46: { 
                makeToken(snooperParsersym.TK_LEFT_SHIFT_EQUAL);
                  break;
            }
    
            //
            // Rule 47:  Token ::= | |
            //
            case 47: { 
                makeToken(snooperParsersym.TK_OR_OR);
                  break;
            }
    
            //
            // Rule 48:  Token ::= & &
            //
            case 48: { 
                makeToken(snooperParsersym.TK_AND_AND);
                  break;
            }
    
            //
            // Rule 49:  Token ::= . . .
            //
            case 49: { 
                makeToken(snooperParsersym.TK_ELLIPSIS);
                  break;
            }
    
            //
            // Rule 50:  Token ::= $
            //
            case 50: { 
                makeToken(snooperParsersym.TK_DollarSign);
                  break;
            }
    
            //
            // Rule 51:  Token ::= HexMacroPrefix
            //
            case 51: { 
            makeToken(snooperParsersym.TK_HEX_MACRO_PREFIX);
                break;
            }

    //#line 243 "LexerTemplateF.gi

    
            default:
                break;
        }
        return;
    }
}

    //#line 6 "LexerBasicMapF.gi
 
  class  snooperLexerLpgLexStream  extends LpgLexStream
    {
     static  final  List<int> tokenKind = [
        snooperLexersym.Char_CtlCharNotWS,    // 000    0x00
        snooperLexersym.Char_CtlCharNotWS,    // 001    0x01
        snooperLexersym.Char_CtlCharNotWS,    // 002    0x02
        snooperLexersym.Char_CtlCharNotWS,    // 003    0x03
        snooperLexersym.Char_CtlCharNotWS,    // 004    0x04
        snooperLexersym.Char_CtlCharNotWS,    // 005    0x05
        snooperLexersym.Char_CtlCharNotWS,    // 006    0x06
        snooperLexersym.Char_CtlCharNotWS,    // 007    0x07
        snooperLexersym.Char_CtlCharNotWS,    // 008    0x08
        snooperLexersym.Char_HT,              // 009    0x09
        snooperLexersym.Char_LF,              // 010    0x0A
        snooperLexersym.Char_CtlCharNotWS,    // 011    0x0B
        snooperLexersym.Char_FF,              // 012    0x0C
        snooperLexersym.Char_CR,              // 013    0x0D
        snooperLexersym.Char_CtlCharNotWS,    // 014    0x0E
        snooperLexersym.Char_CtlCharNotWS,    // 015    0x0F
        snooperLexersym.Char_CtlCharNotWS,    // 016    0x10
        snooperLexersym.Char_CtlCharNotWS,    // 017    0x11
        snooperLexersym.Char_CtlCharNotWS,    // 018    0x12
        snooperLexersym.Char_CtlCharNotWS,    // 019    0x13
        snooperLexersym.Char_CtlCharNotWS,    // 020    0x14
        snooperLexersym.Char_CtlCharNotWS,    // 021    0x15
        snooperLexersym.Char_CtlCharNotWS,    // 022    0x16
        snooperLexersym.Char_CtlCharNotWS,    // 023    0x17
        snooperLexersym.Char_CtlCharNotWS,    // 024    0x18
        snooperLexersym.Char_CtlCharNotWS,    // 025    0x19
        snooperLexersym.Char_CtlCharNotWS,    // 026    0x1A
        snooperLexersym.Char_CtlCharNotWS,    // 027    0x1B
        snooperLexersym.Char_CtlCharNotWS,    // 028    0x1C
        snooperLexersym.Char_CtlCharNotWS,    // 029    0x1D
        snooperLexersym.Char_CtlCharNotWS,    // 030    0x1E
        snooperLexersym.Char_CtlCharNotWS,    // 031    0x1F
        snooperLexersym.Char_Space,           // 032    0x20
        snooperLexersym.Char_Exclamation,     // 033    0x21
        snooperLexersym.Char_DoubleQuote,     // 034    0x22
        snooperLexersym.Char_Sharp,           // 035    0x23
        snooperLexersym.Char_DollarSign,      // 036    0x24
        snooperLexersym.Char_Percent,         // 037    0x25
        snooperLexersym.Char_Ampersand,       // 038    0x26
        snooperLexersym.Char_SingleQuote,     // 039    0x27
        snooperLexersym.Char_LeftParen,       // 040    0x28
        snooperLexersym.Char_RightParen,      // 041    0x29
        snooperLexersym.Char_Star,            // 042    0x2A
        snooperLexersym.Char_Plus,            // 043    0x2B
        snooperLexersym.Char_Comma,           // 044    0x2C
        snooperLexersym.Char_Minus,           // 045    0x2D
        snooperLexersym.Char_Dot,             // 046    0x2E
        snooperLexersym.Char_Slash,           // 047    0x2F
        snooperLexersym.Char_0,               // 048    0x30
        snooperLexersym.Char_1,               // 049    0x31
        snooperLexersym.Char_2,               // 050    0x32
        snooperLexersym.Char_3,               // 051    0x33
        snooperLexersym.Char_4,               // 052    0x34
        snooperLexersym.Char_5,               // 053    0x35
        snooperLexersym.Char_6,               // 054    0x36
        snooperLexersym.Char_7,               // 055    0x37
        snooperLexersym.Char_8,               // 056    0x38
        snooperLexersym.Char_9,               // 057    0x39
        snooperLexersym.Char_Colon,           // 058    0x3A
        snooperLexersym.Char_SemiColon,       // 059    0x3B
        snooperLexersym.Char_LessThan,        // 060    0x3C
        snooperLexersym.Char_Equal,           // 061    0x3D
        snooperLexersym.Char_GreaterThan,     // 062    0x3E
        snooperLexersym.Char_QuestionMark,    // 063    0x3F
        snooperLexersym.Char_AtSign,          // 064    0x40
        snooperLexersym.Char_A,               // 065    0x41
        snooperLexersym.Char_B,               // 066    0x42
        snooperLexersym.Char_C,               // 067    0x43
        snooperLexersym.Char_D,               // 068    0x44
        snooperLexersym.Char_E,               // 069    0x45
        snooperLexersym.Char_F,               // 070    0x46
        snooperLexersym.Char_G,               // 071    0x47
        snooperLexersym.Char_H,               // 072    0x48
        snooperLexersym.Char_I,               // 073    0x49
        snooperLexersym.Char_J,               // 074    0x4A
        snooperLexersym.Char_K,               // 075    0x4B
        snooperLexersym.Char_L,               // 076    0x4C
        snooperLexersym.Char_M,               // 077    0x4D
        snooperLexersym.Char_N,               // 078    0x4E
        snooperLexersym.Char_O,               // 079    0x4F
        snooperLexersym.Char_P,               // 080    0x50
        snooperLexersym.Char_Q,               // 081    0x51
        snooperLexersym.Char_R,               // 082    0x52
        snooperLexersym.Char_S,               // 083    0x53
        snooperLexersym.Char_T,               // 084    0x54
        snooperLexersym.Char_U,               // 085    0x55
        snooperLexersym.Char_V,               // 086    0x56
        snooperLexersym.Char_W,               // 087    0x57
        snooperLexersym.Char_X,               // 088    0x58
        snooperLexersym.Char_Y,               // 089    0x59
        snooperLexersym.Char_Z,               // 090    0x5A
        snooperLexersym.Char_LeftBracket,     // 091    0x5B
        snooperLexersym.Char_BackSlash,       // 092    0x5C
        snooperLexersym.Char_RightBracket,    // 093    0x5D
        snooperLexersym.Char_Caret,           // 094    0x5E
        snooperLexersym.Char__,               // 095    0x5F
        snooperLexersym.Char_BackQuote,       // 096    0x60
        snooperLexersym.Char_a,               // 097    0x61
        snooperLexersym.Char_b,               // 098    0x62
        snooperLexersym.Char_c,               // 099    0x63
        snooperLexersym.Char_d,               // 100    0x64
        snooperLexersym.Char_e,               // 101    0x65
        snooperLexersym.Char_f,               // 102    0x66
        snooperLexersym.Char_g,               // 103    0x67
        snooperLexersym.Char_h,               // 104    0x68
        snooperLexersym.Char_i,               // 105    0x69
        snooperLexersym.Char_j,               // 106    0x6A
        snooperLexersym.Char_k,               // 107    0x6B
        snooperLexersym.Char_l,               // 108    0x6C
        snooperLexersym.Char_m,               // 109    0x6D
        snooperLexersym.Char_n,               // 110    0x6E
        snooperLexersym.Char_o,               // 111    0x6F
        snooperLexersym.Char_p,               // 112    0x70
        snooperLexersym.Char_q,               // 113    0x71
        snooperLexersym.Char_r,               // 114    0x72
        snooperLexersym.Char_s,               // 115    0x73
        snooperLexersym.Char_t,               // 116    0x74
        snooperLexersym.Char_u,               // 117    0x75
        snooperLexersym.Char_v,               // 118    0x76
        snooperLexersym.Char_w,               // 119    0x77
        snooperLexersym.Char_x,               // 120    0x78
        snooperLexersym.Char_y,               // 121    0x79
        snooperLexersym.Char_z,               // 122    0x7A
        snooperLexersym.Char_LeftBrace,       // 123    0x7B
        snooperLexersym.Char_VerticalBar,     // 124    0x7C
        snooperLexersym.Char_RightBrace,      // 125    0x7D
        snooperLexersym.Char_Tilde,           // 126    0x7E

        snooperLexersym.Char_AfterASCII,      // for all chars in range 128..65534
        snooperLexersym.Char_EOF              // for '\uffff' or 65535 
    ];
            
     int  getKind(int i)// Classify character at ith location
    {
        var c = (i >= getStreamLength() ? 0xffff : getIntValue(i));
        return (c < 128 // ASCII Character
                  ? snooperLexerLpgLexStream.tokenKind[c]
                  : c == 0xffff 
                       ? snooperLexersym.Char_EOF
                       : snooperLexersym.Char_AfterASCII);
    }

    List<String> orderedExportedSymbols(){ return snooperParsersym.orderedTerminalSymbols; }

  
    snooperLexerLpgLexStream(String fileName, [String? inputChars,int tab=4])
    :super(fileName, inputChars, tab);
    }

